import request from "@/utils/request";

/**
 * 分页查询菜单
 */
export async function pageMenus(params) {
  const res = await request.get("/system/menu/page", { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询菜单列表
 */
export async function listMenus(params) {
  const res = await request.get("/system/menu", {
    params,
  });
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询用户
 */
export async function getMenu(id) {
  const res = await request.get("/system/menu/" + id);
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加菜单
 */
export async function addMenu(data) {
  const res = await request.post("/system/menu", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改菜单
 */
export async function updateMenu(data) {
  const res = await request.put("/system/menu/" + data.menu_id, data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除菜单
 */
export async function removeMenu(id) {
  const res = await request.delete("/system/menu/" + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除菜单
 */
export async function removeMenuBatch(data) {
  const res = await request.delete("/system/menu/batch", { data });
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
